using System;
using System.Text;
using System.Drawing;

#if (WinForms)
  using System.Windows.Forms;
#else
  using cs2335.CCT;
#endif

namespace cs2335.lab6
{
    #if (WinForms)
	class Demo1 : Form
    #else
	class Demo1 : CCTForm
    #endif
    {

	int count;
        System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();

	Button startButton = new Button();
        Button pauseButton = new Button();
        Button resetButton = new Button();
        ProgressBar pb = new ProgressBar();
        Label countDownLabel = new Label();
        Label bang = new Label();


        public Demo1()
        {
            timer.Interval = 1000;
            timer.Tick += new EventHandler(timer_tick);

            startButton.Text = "start";
            startButton.Click += new EventHandler(startButton_Click);
            startButton.Location = new Point(20, 20);

            pauseButton.Text = "pause";
            pauseButton.Click += new EventHandler(pauseButton_Click);
            pauseButton.Location = new Point(20, 60);


            resetButton.Text = "reset";
            resetButton.Click += new EventHandler(resetButton_Click);
            resetButton.Location = new Point(20, 100);

            countDownLabel.Location = new Point(150, 65);

            bang.Font = new Font("SansSerif", 18);
            bang.Location = new Point(150, 20);
            bang.Text = "BANG";
            bang.Hide();

            pb.Step = 1;
            pb.Minimum = 0;
            pb.Maximum = 30;
            pb.Location = new Point(150, 100);

            count = 30;
            pb.Value = 30;
            countDownLabel.Text = "00:" + count;

            

	    #if (WinForms)
            	////Use these to run with Windows.Forms////
            	this.Controls.Add(startButton);
            	this.Controls.Add(pauseButton);
            	this.Controls.Add(resetButton);
            	this.Controls.Add(countDownLabel);
            	this.Controls.Add(pb);
            	this.Controls.Add(bang);
	    #else
            	///////Use these to run with CCT////////
            	this.Add(startButton);
            	this.Add(pauseButton);
            	this.Add(resetButton);
            	this.Add(countDownLabel);
            	this.Add(pb);
            	this.Add(bang);
	    #endif
            


        }

        void resetButton_Click(object sender, EventArgs e)
        {
            bang.Hide();
            count = 30;
            pb.Value = count;
            countDownLabel.Text = "00:" + count;
            this.Invalidate();
        }

        void pauseButton_Click(object sender, EventArgs e)
        {
            timer.Enabled = false;
        }

        void startButton_Click(object sender, EventArgs e)
        {
            timer.Enabled = true;
        }
        

        private void timer_tick(object sender, EventArgs e)
        {
            if (count > 0)
            {
                count--;
                pb.Value = count;
                countDownLabel.Text = "00:" + count;
                this.Invalidate();
            }
            else
            {
                timer.Enabled = false;
            }

            if (count == 0)
            {
                bang.Show();
            }
        }


        
        public static void Main()
        {
            System.Windows.Forms.Application.Run(new Demo1());
        }
        

        
    }
}
